//
//  AnimationViewController.swift
//  swift各类控件集锦
//
//  Created by iosdev1 on 2017/1/5.
//  Copyright © 2017年 zyy. All rights reserved.
//

import UIKit

class AnimationViewController: ZyBaseViewController {

    var i:NSInteger = 2

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.

        self.title = "动画"
        let lblTitle:UILabel = UILabel.init(frame: CGRect(x:(WIDTH_SCREEN - 100)/2, y:100, width:100, height:30))
        self.view.addSubview(lblTitle)
        lblTitle.text = "测试动画"
        lblTitle.textColor = UIColor.black
        
        let btnAni:UIButton = UIButton.init(frame: CGRect(x:100, y:500, width:100, height:30))
        self.view.addSubview(btnAni)
        btnAni.setTitle("上升", for: UIControlState.normal)
        btnAni.setTitleColor(UIColor.black, for: UIControlState.normal)
        btnAni.addTarget(self, action: #selector(btnAniClick(sender:)), for: UIControlEvents.touchUpInside)


        let imageView:UIImageView = UIImageView.init(frame: CGRect(x:10, y:70, width:50, height:50))
        self.view.addSubview(imageView);
        imageView.image = UIImage.init(named: "xph1")
        imageView.tag = 1000

    }
    
    func btnAniClick(sender:UIButton) -> Void {
        UIView.animate(withDuration: 2.0) {
            let imageView = self.view.viewWithTag(1000) as! UIImageView
            let imageStr = "xph" + "\(self.i)"
            imageView.image = UIImage.init(named: imageStr)
            imageView.frame = CGRect(x:(10 + self.i * 4), y:(70 + self.i * 4), width:50, height:50)
            if self.i == 12 {
                self.i = 1;
            }else {
                self.i = self.i + 1;
            }
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
